const Mock = require('mockjs')

const data = Mock.mock({
  'items|30': [{
    id: '@id',
    positionId: '@id',
    appCode: '@integer(0, 40)',
    appName: '@cword(2,5)',
    'statusFlag|1': ['published', 'draft', 'deleted'],
    appIcon: '@csentence(200)',
    appSort: '@integer(0, 40)'
  }]
})
module.exports = [
  // 查询列表
  {
    url: '/hrPosition/page',
    type: 'get',
    response: (config) => {
      const { items } = data
      // config是传进来的参数对象
      const { pageNo = 1, pageSize = 10 } = config.query
      const pageList = items.filter((item, index) => index < pageSize * pageNo && index >= pageSize * (pageNo - 1))
      return {
        code: '00000',
        data: {
          totalRows: items.length,
          rows: pageList
        }
      }
    }
  },
  // 添加
  {
    url: '/hrPosition/add',
    type: 'post',
    response: (_) => {
      return {
        code: '00000',
        data: 'success'
      }
    }
  },
  // 修改
  {
    url: '/hrPosition/edit',
    type: 'post',
    response: (_) => {
      return {
        code: '00000',
        data: 'success'
      }
    }
  },
  // 详情
  {
    url: '/hrPosition/detail',
    type: 'get',
    response: (config) => {
      const { items } = data
      const { positionId } = config.query
      for (const item of items) {
        if (item.positionId === positionId) {
          return {
            code: '00000',
            data: item
          }
        }
      }
    }
  },
  // 删除
  {
    url: '/hrPosition/delete',
    type: 'post',
    response: (_) => {
      return {
        code: '00000',
        data: 'success'
      }
    }
  },
  // 修改状态
  {
    url: '/hrPosition/updateStatus',
    type: 'get',
    response: (config) => {
      const { items } = data
      const { positionId } = config.query
      for (const item of items) {
        if (item.positionId === positionId) {
          return {
            code: '00000',
            data: item
          }
        }
      }
    }
  },
  // 导出
  {
    url: '/hrPosition/exportPostion',
    type: 'get',
    responseType: 'arraybuffer',
    response: (config) => {
      const { items } = data
      return {
        code: '00000',
        data: items
      }
    }
  }
]
